package edu.xjdx.os.utils;

import com.github.pagehelper.PageInfo;
import edu.xjdx.os.domain.Goods;
import edu.xjdx.os.domain.Pages;

import java.util.List;

public class PageUtil{
    public static Pages getPageInfo(List<Goods> objects){
        if (objects==null){
            Pages page=new Pages();
            page.setTotalNum(0);
            page.setTotalPages(0);
            return page;
        }
        PageInfo pageInfo=new PageInfo(objects);
        Pages page=new Pages();
        int pageNum=pageInfo.getPageNum();
        int pageSize=pageInfo.getPageSize();
        page.setTotalPages(pageInfo.getPages());
        page.setTotalNum((int) pageInfo.getTotal());
        page.setPageNum(pageNum);
        page.setPageSize(pageSize);
        page.setScopeLeft((pageNum-1)*pageSize+1);
        if (pageNum==page.getTotalPages()){
            page.setScopeRight(page.getTotalNum());
        }else{
            page.setScopeRight(pageNum*pageSize);
        }
        return page;
    }
}
